package demo1;

import java.util.Arrays;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    public String multiply(String num1, String num2) {
        int n1 = num1.length()-1;
        int n2 = num2.length()-1;
        if(n1 < 0 || n2 < 0) return "";
        int[] mul = new int[n1+n2+2];

        for(int i = n1; i >= 0; --i) {
            for(int j = n2; j >= 0; --j) {
                int bitmul = (num1.charAt(i)-'0') * (num2.charAt(j)-'0');
                bitmul += mul[i+j+1]; // 先加低位判断是否有新的进位

                mul[i+j] += bitmul / 10;
                mul[i+j+1] = bitmul % 10;
            }
        }

        StringBuilder sb = new StringBuilder();
        int i = 0;
        // 去掉前导0
        while(i < mul.length-1 && mul[i] == 0)
            i++;
        for(; i < mul.length; ++i)
            sb.append(mul[i]);
        return sb.toString();
    }


    public int search(int[] nums, int target) {
        int le = 0;
        int re = nums.length - 1;
        while(re >= le){
            if(nums[re] > target) re --;
            else if(nums[le] < target) le ++;
            else if(nums[le] == target) return le;
            else if(nums[re] == target) return re;
            else return -1;
        }
        return -1;
    }

    //执行操作可获得的最大总奖励
    public int maxTotalReward(int[] rewardValues) {
        int sum = 0;
        int n = rewardValues.length;
        Arrays.sort(rewardValues);
        for (int left = 0,right=n-1;right<n;) {

        }
        return 1;
    }
}
